﻿package net.wangit.jdbc.sqltype;

import java.sql.Types;

/**
 * SQL数据类型工厂类
 * 
 * @author watson Feb 12, 2010
 */
public class SqlTypeFactory {
	public static final SqlType CHAR = new CharacterSqlType();

	public static final SqlType VARCHAR = new StringSqlType();

	public static final SqlType SMALLINT = new ShortSqlType();

	public static final SqlType INTEGER = new IntegerSqlType();

	public static final SqlType BIGINT = new LongSqlType();

	public static final SqlType FLOAT = new FloatSqlType();

	public static final SqlType DOUBLE = new DoubleSqlType();

	public static final SqlType DECIMAL = new BigDecimalSqlType();

	public static final SqlType DATE = new DateSqlType();

	public static final SqlType TIME = new TimeSqlType();

	public static final SqlType TIMESTAMP = new TimestampSqlType();

	public static final SqlType CLOB = new ClobSqlType();

	public static final SqlType BLOB = new BlobSqlType();

	public static SqlType getSqlType(int sqlTypeCode) {
		switch (sqlTypeCode) {
		case Types.CHAR:
			return CHAR;
		case Types.LONGVARCHAR:
		case Types.VARCHAR:
		case Types.OTHER:
			return VARCHAR;
		case Types.TINYINT:
		case Types.SMALLINT:
			return SMALLINT;
		case Types.INTEGER:
			return INTEGER;
		case Types.BIGINT:
			return BIGINT;
		case Types.FLOAT:
		case Types.REAL:
			return FLOAT;
		case Types.DOUBLE:
			return DOUBLE;
		case Types.NUMERIC:
		case Types.DECIMAL:
			return DECIMAL;
		case Types.DATE:
			return DATE;
		case Types.TIME:
			return TIME;
		case Types.TIMESTAMP:
			return TIMESTAMP;
		case Types.CLOB:
			return CLOB;
		case Types.LONGVARBINARY:
		case Types.VARBINARY:
		case Types.BINARY:
		case Types.BLOB:
			return BLOB;
		}
		throw new UnsupportedOperationException("Unsupported type: "
				+ sqlTypeCode);
	}
}